package br.com.jk.cidade;

import br.com.jk.uf.Uf;
import java.io.Serializable;
import java.util.Objects;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.hibernate.annotations.ForeignKey;

/**
 *
 * @author camilo
 */
@Entity
@Table(name = "cidade")
public class Cidade implements Serializable {

  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private int id;
  private String descricao;
  @ManyToOne
  @JoinColumn(name = "id_uf", nullable = false)
  @ForeignKey(name = "fk_cidade_uf")
  private Uf uf;

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public String getDescricao() {
    return descricao;
  }

  public void setDescricao(String descricao) {
    this.descricao = descricao;
  }

  public Uf getUf() {
    return uf;
  }

  public void setUf(Uf uf) {
    this.uf = uf;
  }

  @Override
  public int hashCode() {
    int hash = 7;
    hash = 61 * hash + this.id;
    hash = 61 * hash + Objects.hashCode(this.descricao);
    hash = 61 * hash + Objects.hashCode(this.uf);
    return hash;
  }

  @Override
  public boolean equals(Object obj) {
    if (obj == null) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }
    final Cidade other = (Cidade) obj;
    if (this.id != other.id) {
      return false;
    }
    if (!Objects.equals(this.descricao, other.descricao)) {
      return false;
    }
    if (!Objects.equals(this.uf, other.uf)) {
      return false;
    }
    return true;
  }
}
